from src.common.logger import getLogger
from datetime import datetime, timedelta
from src.common.ScheduleMessage import ScheduleMessage
from apscheduler.schedulers.background import BackgroundScheduler

logger = getLogger()

class ScheduleTaskPool:

    def __init__(self):
        logger.info("ScheduleTaskPool init")

    def init_schedule_pool(self):
        logger.info("ScheduleTaskPool start config BackgroundScheduler")
        first_run_time = datetime.now() + timedelta(seconds = 5)
        message_schedule = ScheduleMessage().init_schedule_message

        scheduler = BackgroundScheduler()
        scheduler.add_job(func = message_schedule, trigger = "interval", start_date = first_run_time, seconds = 600)
        scheduler.start()
        logger.info("ScheduleTaskPool config BackgroundScheduler finished")
